<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>class RubyXL::ColumnRanges - rubyXL 3.4.35</title>


  <meta name="keywords" content="ruby,class,RubyXL::ColumnRanges">


    <meta name="description" content="Documentation for the RubyXL::ColumnRanges class">





<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
</script>

<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="class">
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
  <span aria-hidden="true">&#9776;</span>
</div>


<nav id="navigation" role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  

  
<div id="parent-class-section" class="nav-section">
  <h3>Ancestors</h3>
  <ul><li>OOXMLContainerObject</li></ul>
</div>


  

  

  


  <div class="nav-section">
    <h3>Instance Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-i-before_write_xml">before_write_xml</a></li>

      <li ><a href="#method-i-get_range">get_range</a></li>

      <li ><a href="#method-i-insert_column">insert_column</a></li>

      <li ><a href="#method-i-locate_range">locate_range</a></li>

    </ul>
  </div>



  <footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a></p>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.15.1.</p>
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
</footer>

</nav>

<main role="main" aria-labelledby="class-RubyXL::ColumnRanges">
  
  
    <ol role="navigation" aria-label="Breadcrumb navigation" class="breadcrumb">
      
      <li>
        
        <a href="../RubyXL.html">RubyXL</a><span>::</span>
        
      </li>
      
      <li>
        
        <span>ColumnRanges</span>
        
      </li>
      
    </ol>
  

  <h1 id="class-RubyXL::ColumnRanges" class="anchor-link class">
    class RubyXL::ColumnRanges
  </h1>

  <section class="description">
    
  </section>


  <section id="5Buntitled-5D" class="documentation-section anchor-link">









     <section id="public-instance-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Instance Methods</h3>
       </header>


      <div id="method-i-before_write_xml" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-before_write_xml" title="Link to this method">
                <span class="method-name">before_write_xml</span>
                <span class="method-args">()</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="before_write_xml-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/column_range.rb, line 88</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">before_write_xml</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">sort_by!</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:min</span>)
  <span class="ruby-operator">!</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-get_range" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-get_range" title="Link to this method">
                <span class="method-name">get_range</span>
                <span class="method-args">(col_index)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="get_range-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/column_range.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_range</span>(<span class="ruby-identifier">col_index</span>)
  <span class="ruby-identifier">col_num</span> = <span class="ruby-identifier">col_index</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>

  <span class="ruby-identifier">old_range</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">locate_range</span>(<span class="ruby-identifier">col_index</span>)

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">new_range</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">width:</span> <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnRange</span>.<span class="ruby-identifier">chars2raw</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnRange</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_WIDTH</span>))
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">min</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_num</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">max</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_num</span> <span class="ruby-keyword">then</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">old_range</span> <span class="ruby-comment"># Single column range, OK to change in place</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">min</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_num</span> <span class="ruby-keyword">then</span>
      <span class="ruby-identifier">new_range</span> = <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">dup</span>
      <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">min</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">max</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">col_num</span> <span class="ruby-keyword">then</span>
      <span class="ruby-identifier">new_range</span> = <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">dup</span>
      <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">max</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">prior_range</span> = <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">dup</span>
      <span class="ruby-identifier">prior_range</span>.<span class="ruby-identifier">max</span> = <span class="ruby-identifier">col_index</span> <span class="ruby-comment"># col_num - 1</span>
      <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">prior_range</span>

      <span class="ruby-identifier">old_range</span>.<span class="ruby-identifier">min</span> = <span class="ruby-identifier">col_num</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>

      <span class="ruby-identifier">new_range</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnRange</span>.<span class="ruby-identifier">new</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">new_range</span>.<span class="ruby-identifier">min</span> = <span class="ruby-identifier">new_range</span>.<span class="ruby-identifier">max</span> = <span class="ruby-identifier">col_num</span>
  <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">new_range</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">new_range</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Locate an existing column range, make a new one if not found, or split existing column range into multiples.</p>


        </div>





      </div>


      <div id="method-i-insert_column" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-insert_column" title="Link to this method">
                <span class="method-name">insert_column</span>
                <span class="method-args">(col_index)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="insert_column-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/column_range.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">insert_column</span>(<span class="ruby-identifier">col_index</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">range</span><span class="ruby-operator">|</span> <span class="ruby-identifier">range</span>.<span class="ruby-identifier">insert_column</span>(<span class="ruby-identifier">col_index</span>) }
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


      <div id="method-i-locate_range" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-locate_range" title="Link to this method">
                <span class="method-name">locate_range</span>
                <span class="method-args">(col_index)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="locate_range-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/column_range.rb, line 80</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">locate_range</span>(<span class="ruby-identifier">col_index</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">range</span><span class="ruby-operator">|</span> <span class="ruby-identifier">range</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">col_index</span>) }
<span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

  </section>

</main>
</body>

